package cn.myjerry.net.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

/**
 * 客户端
 * 1、创建客户端
 * 2、准备数据
 * 3、打包
 * 4、发送
 * 5、释放
 * @author Jerry
 *
 */
public class MyClient {
	public static void main(String[] args) throws IOException {
		DatagramSocket client = new DatagramSocket(6666);
		
		String msg = "test data";
		byte[] b = msg.getBytes();
		//byte buf[], int offset, int length, SocketAddress address
		DatagramPacket packet = new DatagramPacket(b, 0, b.length, new InetSocketAddress("localhost", 8888));
		
		client.send(packet);
		
		client.close();
	}
}
